home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / pctecap.arc / INTRACE.ASM < prev    next >
Assembly Source File  |  1986-03-15  |  4KB  |  240 lines

  1.     page    56,132
  2.     title    INTRACE Display whenever an interrupt type 2 occurs
  3.     .sall
  4. ;
  5. ; Program to display the interrupted address whenever an interrupt 
  6. ; of type 2 occurs.  This is used to find out where MultiLink is writing
  7. ; to the IBM Prototype Board.
  8. ;
  9. ; If this program seems to have some superfluous code, it's because it
  10. ; was originally used in tracing disk I/O calls to debug a device
  11. ; driver...
  12. ;
  13.  
  14. ;
  15. ; Macros
  16. ;
  17.  
  18. ;
  19. ; wto: write message to display.  Append cr/lf unless crsup=nocr
  20. ;
  21.  
  22. wto    macro    msg,crsup
  23.     local    msgstr,around
  24.  
  25.     jmp    around
  26.  
  27. msgstr    db    msg
  28.     ifb    <crsup>
  29.     db    0DH,0AH
  30.     endif
  31.     db    '$'
  32.  
  33. around:    push    ax
  34.     push    bx
  35.     push    si
  36.     push    di
  37.     push    bp
  38.  
  39.     mov    si,offset msgstr
  40.     call    putc
  41.  
  42.     pop    bp
  43.     pop    di
  44.     pop    si
  45.     pop    bx
  46.     pop    ax
  47.  
  48.     endm
  49.  
  50. prtreg    macro    rg,msg    ; put register rg with message msg on display
  51.  
  52.     push    ax
  53.  
  54.     mov    ax,rg
  55.     call    prtax
  56.     wto    msg,nocr
  57.  
  58.     pop    ax
  59.     endm
  60.  
  61.  
  62. ;
  63. ; Code Segment
  64. ;
  65.  
  66. cseg        segment para public 'code'
  67.         assume    cs:cseg,ds:cseg,ss:cseg,es:nothing
  68.  
  69.         org    100H
  70. ;
  71. ; COM program startup
  72. ;
  73. cpstart        proc    far
  74.         jmp    near ptr start
  75. cpstart        endp
  76.  
  77. ;
  78. ; Local Procedures
  79. ;
  80. putc        proc    near    ; write a string to display W/O DOS intervention
  81.         mov    bl,7    ; Parameter setup same as for DOS's write-string
  82.         mov    bh,0    ; function
  83. putc1:
  84.         mov    al,cs:[si]
  85.         cmp    al,'$'
  86.         je    putc2
  87.         mov    ah,14
  88.         int    10H
  89.         inc    si
  90.         jmp    putc1
  91.  
  92. putc2:
  93.         ret
  94. putc        endp
  95.  
  96. prtnum        proc    near    ; print half a byte on screen
  97.         push    ds    ; this procedure is used by prtax below
  98.         push    cs
  99.         pop    ds
  100.         push    bx
  101.         mov    bx,offset xltab
  102.         xlatb
  103.         mov    ah,14
  104.         mov    bh,0
  105.         int    10h
  106.         pop    bx
  107.         pop    ds
  108.         ret
  109. xltab        db    '0123456789ABCDEF'
  110. prtnum        endp
  111.  
  112. prtax        proc    near    ; print contents of ax register on screen
  113.         push    cx    ; all registers are preserved
  114.         push    ax
  115.         mov    al,ah
  116.         mov    cl,4
  117.         shr    al,cl
  118.         call    prtnum
  119.         pop    ax
  120.         push    ax
  121.         mov    al,ah
  122.         and    al,0Fh
  123.         call    prtnum
  124.         pop    ax
  125.         push    ax
  126.         mov    cl,4
  127.         shr    al,cl
  128.         call    prtnum
  129.         pop    ax
  130.         push    ax
  131.         and    al,0Fh
  132.         call    prtnum
  133.         pop    ax
  134.         pop    cx
  135.         ret
  136. prtax        endp
  137.  
  138. ;
  139. ; this routine does the actual display of the interrupted location
  140. ;
  141.  
  142. sssav        dw    ?
  143. spsav        dw    ?
  144. axsav        dw    ?
  145.  
  146. lsbottom    db    1024 dup (?)
  147. lstack        dw    0
  148.  
  149. tracer        proc    near
  150.  
  151.         ;
  152.         ; establish our environment
  153.         ; we turn off ints here for old 8088s with defective microcode
  154.         ; (e.g., mine)
  155.         ;
  156.  
  157.         cli
  158.         mov    cs:axsav,ax        ; switch stacks
  159.         mov    cs:sssav,ss
  160.         mov    cs:spsav,sp
  161.         mov    ax,cs
  162.         mov    ss,ax
  163.         mov    sp,offset lstack
  164.         sti
  165.  
  166.         mov    ax,cs:axsav        ; get ax back
  167.  
  168.         ;
  169.         ; print address to which the RTI will return
  170.         ;
  171.  
  172.         push    ax
  173.         push    bx
  174.         push    es
  175.  
  176.         mov    es,cs:sssav
  177.         mov    bx,cs:spsav
  178.  
  179.         wto    "int2: ",nocr
  180.         prtreg    es:2[bx],":"
  181.         prtreg    es:[bx]," "
  182.         wto    " "
  183.  
  184.         pop    es
  185.         pop    bx
  186.         pop    ax
  187.  
  188.         mov    al,20H        ; signal EOI
  189.         out    20H,al
  190.         mov    ax,cs:axsav
  191.  
  192.         ;
  193.         ; reestablish original environment
  194.         ;
  195.  
  196.         cli                ; restore stack
  197.         mov    ss,cs:sssav
  198.         mov    sp,cs:spsav
  199.         sti
  200.  
  201.         iret
  202.  
  203. tracer        endp
  204.  
  205. ;
  206. ; everything below this point will be deleted from memory once the initial
  207. ; command exits
  208. ;
  209.  
  210. start        proc    near
  211.  
  212.         wto    "Installing interrupt trace."
  213.         mov    ax,0
  214.         mov    es,ax
  215.  
  216.         mov    ax,offset tracer
  217.         mov    word ptr es:28H,ax
  218.         mov    ax,cs
  219.         mov    word ptr es:2aH,ax
  220.  
  221.         wto    "Enabling interrupt"
  222.  
  223.         mov    al,0B8H
  224.         out    21H,al
  225.         mov    al,20H
  226.         out    20H,al
  227.  
  228.         wto    "Interrupt enabled"
  229.  
  230.         wto    "Installation complete; executing TSR."
  231.         mov    dx,offset start
  232.         add    dx,100H ; a little extra space...
  233.         int    27H
  234.  
  235. start        endp
  236.  
  237. cseg        ends
  238.  
  239.         end    cpstart
  240.